home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / SML⁄NJ 93+ / Documentation / examples / awk / tally.sml < prev   
Encoding:
Text File  |  1995-12-30  |  388 b   |  20 lines  |  [TEXT/R*ch]

  1. structure Table = StringTable(type elem = int val default = 0);
  2.  
  3. val table = Table.new();
  4.  
  5. fun step (fields: string list) =
  6.     let val name::value::_ = fields
  7.      in Table.set table (name, Table.get table name + Awk.makeInt value)
  8.     end
  9.  
  10. fun final () =
  11.     Table.app table (fn (s,n) => (print s; print "\t"; print n; print "\n";()))
  12.  
  13. (* invoke by
  14.  
  15.    Awk.awk(stream,step,final)
  16.  
  17. *)
  18.  
  19.  
  20.